package com.fusion.lottery.auth.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.fusion.lottery.auth.service.SourceService;
import com.fusion.lottery.entity.auth.Source;
import com.fusion.utils.json.Msg;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

/**
 * 
 * @author louis
 *
 */
@Api(description="权限操作接口")
@RestController
@RequestMapping(value = "/source")
public class SourceController {
	
	@Autowired
	private SourceService sourceService;
	
	@ApiOperation(value="获取权限列表", notes="获取权限列表")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "start", value = "起始记录", required = false, dataType = "Long" ,paramType = "query"),
		@ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Long" ,paramType = "query")
	})
	@GetMapping
	public Msg getUsers(
			@RequestParam(defaultValue = "20", required = false, value = "pageSize") int pageSize,
			@RequestParam(defaultValue = "0", required = false, value = "start") int start,
			Source source) {
		return sourceService.list(source,start,pageSize);
	}
	
	@ApiOperation(value="获取权限信息", notes="获取权限信息")
	@ApiImplicitParam(name = "id", value = "权限id", required = true, dataType = "Long",paramType = "path")
	@GetMapping("/{id}")
    public Msg getUser(@PathVariable long id) {
        return sourceService.get(id);
    }
    
	@ApiOperation(value="修改权限", notes="修改权限")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "id", value = "权限id", required = true, dataType = "int",paramType = "path"),
		@ApiImplicitParam(name = "source", value = "权限实体", required = true, dataType = "Source")
	})
    @PutMapping("/{id}")
    public Msg update(@PathVariable int id, @RequestBody Source source) {
		source.setId(id);
		return sourceService.update(source);
    }
	
    
}